package com.jic.point.common;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author bourne
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class RestResult<T> implements Serializable {

    private static final String ERROR_FALSE = "enable.down.point.sNumber.is.null";//消耗积分流水码不能为空
    private static final String SUCCESS_RESULT = "true";


    private String error;
    private T result;
    private boolean success;
    private String Msg;

    public static RestResult error(String error, String result,String success) {
        return RestResult.builder()
                .success(false)
                .result(null)
                .error(ERROR_FALSE)
                .build();
    }
    public static RestResult success(String Msg, String error) {
        return RestResult.builder()
                .error(error)
                .Msg(Msg)
                .build();
    }

    public static <T> RestResult<T> success(String success, T data) {
        return RestResult.<T>builder()
                .success(true)
                .result((T) SUCCESS_RESULT)
                .error(null)
                .build();
    }

//    public static boolean checkIsSuccess(RestResult restResult) {
//        if (restResult != null && SUCCESS_CODE.equals(restResult.getCode())) {
//            return true;
//        }
//        return false;
//    }
}
